/**
 * Copyright (C) 2011, mordredd666 [_at_] gmail.com
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package de.mordred.gui.lernen;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import de.mordred.Main;
import de.mordred.gui.FixedPanel;
import de.mordred.gui.TopLeiste;
import de.mordred.gui.VerticalFlowLayout;

public class ThemaSelection extends FixedPanel
{
	private static final long serialVersionUID = 7173838735084930821L;

	// Multiselection

	private ArrayList<String> _selectedThemen;

	public ThemaSelection(String fach, ArrayList<String> themen)
	{
		_selectedThemen = new ArrayList<String>();
		this.setLayout(new BorderLayout());

		TopLeiste top = new TopLeiste(new FachSelection(Main.getFächer()), getTitel(), null);

		this.add(top, BorderLayout.NORTH);

		JPanel center = new JPanel(new VerticalFlowLayout());
		this.add(center, BorderLayout.CENTER);

		for (final String them : themen)
		{
			final JCheckBox item = new JCheckBox(them);

			center.add(item);
			item.addActionListener(new ActionListener()
			{
				@Override
				public void actionPerformed(ActionEvent e)
				{
					if (item.isSelected())
					{
						_selectedThemen.add(them);
					}
					else
					{
						_selectedThemen.remove(them);
					}
				}
			});
		}

		JButton examina = new JButton("Examina");
		top.add(examina);

		examina.addActionListener(getListener(fach, _selectedThemen));

	}

	@Override
	public String getTitel()
	{
		return "Themen";
	}

	public ActionListener getListener(final String fach, final ArrayList<String> themen)
	{
		return new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent e)
			{
				Main.setNextPanel(new JahrSelection(fach, themen));

			}
		};
	}

}
